package com.three.iot.channel.impl.chinamobile;

import com.aliyun.openservices.iot.api.Profile;
import com.aliyun.openservices.iot.api.message.MessageClientFactory;
import com.aliyun.openservices.iot.api.message.api.MessageClient;
import com.aliyun.openservices.iot.api.message.callback.MessageCallback;
import com.aliyun.openservices.iot.api.message.entity.Message;

/**
 * @author luiz
 * @Title: IotTest
 * @ProjectName iot-server
 * @Description: TODO
 * @date 2019-05-07 13:02
 */
public class IotTest {
    public static void main(String[] args) {
        // 阿里云accessKey
        String accessKey = "LTAIM4zSiZd7rMzu";
        // 阿里云accessSecret
        String accessSecret = "LiKB95DldnjMSGhzrUIcFEqmysb864";
        // regionId
        String regionId = "cn-shanghai";
        // 阿里云uid
        String uid = "1246357047831252";
        // endPoint:  https://${uid}.iot-as-http2.${region}.aliyuncs.com
        String endPoint = "https://" + uid + ".iot-as-http2." + regionId + ".aliyuncs.com";

        // 连接配置
        Profile profile = Profile.getAccessKeyProfile(endPoint, regionId, accessKey, accessSecret);

        // 构造客户端
        MessageClient client = MessageClientFactory.messageClient(profile);

        // 数据接收
        client.connect(messageToken -> {
            Message m = messageToken.getMessage();
            System.out.println("receive message from " + m);
            return MessageCallback.Action.CommitSuccess;
        });
    }
}
